import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PeaceFieldEnterData } from "./data/PeaceFieldEnterData";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class PeaceFieldEnterRender
    
    export  class PeaceFieldEnterRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._btnEnter = ObjCreate.createGLoadedButton(ResFileConst.PeaceFieldBtn, 5, 5, 105, 106, this);
            var loc1=GlobalClass.getBitmap("PeaceFieldText");
            ObjCreate.setObjAttri(loc1, 16, 60, -1, -1, this);
            var loc2=new GTextFormat(FontUtil.EmbedNumberName, 50, 16776960);
            loc2.align = flash.text.TextFormatAlign.CENTER;
            this._tfIndex = new Object /* flash.text.TextField */();
            this._tfIndex.embedFonts = true;
            this._tfIndex.defaultTextFormat = loc2;
            ObjCreate.setObjAttri(this._tfIndex, 0, 10, 105, 50, this);
            this._tfIndex.mouseEnabled = false;
            this._txtNum = ObjCreate.createTextField("(0/50)", 30, 80, 60, 20, this, GlobalStyle.textFormat6);
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnEnterClick);
            return;
        }

        /* internal  */onBtnEnterClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PeaceFieldEnter, this._peaceFieldEnterData.info.fieldId));
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (typeof arg1 === "peacefieldenterdata") 
            {
                this._peaceFieldEnterData = arg1 as PeaceFieldEnterData;
                this.updateView();
            }
            return;
        }

        /* internal  */updateView(): void
        {
            this._tfIndex.text = this._peaceFieldEnterData.index.toString();
            this._btnEnter.enabled = this._peaceFieldEnterData.isCanEnter;
            this._txtNum.text = "(" + this._peaceFieldEnterData.info.playerNum + "/" + this._peaceFieldEnterData.maxNum + ")";
            this._btnEnter.drawNow();
            return;
        }

        /* internal */ /* var */_btnEnter: GLoadedButton;

        /* internal */ /* var */_txtNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfIndex: Object /* flash.text.TextField */;

        /* internal */ /* var */_peaceFieldEnterData: PeaceFieldEnterData;
    }
